// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.

import 'package:dio/dio.dart';
export 'dart:core';
import 'package:connectivity/connectivity.dart';

void main() async {
  Dio dioHttp = Dio();
  dioHttp.options.connectTimeout = 10000; //5s
  dioHttp.options.receiveTimeout = 10000;
  dioHttp.options.headers = {
    'PD-UDID': '6cfac568bb02696d',
    'PD-VERSION': '1.1.1',
    // 'PD-REGION' : AppSession.region ?? '',
  };
  dioHttp.options.validateStatus = (int? status) {
    return (status??0) > 0;
  };
  dioHttp.interceptors.add(LogInterceptor(request: true, responseBody: true)); //Log
  // dioHttp.interceptors.add(ConnectivityInterceptor(dioHttp)); //Connectivity Check
  // final response = await dioHttp.get('https://api.heycard.ca/potato/app/v1/init_load');
  final response = await dioHttp.post('https://api.heycard.ca/potato/app/v1/query_prods');
  print(response.data);
}

class ConnectivityInterceptor extends InterceptorsWrapper {
  final Dio _dio;

  ConnectivityInterceptor(this._dio);

  @override
  onRequest(RequestOptions options,RequestInterceptorHandler handler) async {
    //没有网络
    var connectivityResult = await (new Connectivity().checkConnectivity());
    if (connectivityResult == ConnectivityResult.none) {
       // return _dio.resolve(new Response(statusCode: 901));
    }
     // return options;
  }
}
